<?php

namespace App\Jobs\Train\Snap;

use App\Models\Task\SnapTasks\SnapTask;
use App\Models\Train\TrainOrders\TrainOrder;
use App\Models\Trip\TripOrderRefund\TripOrderRefund;
use Exception;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Throwable;

class ProcessTaskCancelAndRefund implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    private SnapTask   $task;
    private TrainOrder $order;

    /**
     * Create a new job instance.
     *
     * @return void
     */
    public function __construct(SnapTask $task, TrainOrder $order)
    {
        $this->task  = $task;
        $this->order = $order;
    }

    /**
     * Execute the job.
     *
     * @return void
     * @throws Exception
     * @throws Throwable
     */
    public function handle()
    {
        $refund = new TripOrderRefund();
        $refund->applyTaskNoTicketRefund($this->task, $this->order);
    }
}
